#include<iostream>
#include<vector>

using namespace std;

void Print(vector<int> v2)
{
	int j = 0;
	while (j < v2.size())
	{
		cout << v2[j++] << "\t";
	}
	cout << endl;
}
int main()
{
	vector <int> v1 = { 1,2,3,4,5 };
	cout << v1 [4]<<endl;
	cout << v1.at(4)<<endl;

	v1.at(1) = 20;
	int i = 6;
	int k = 5;
	while (v1.size() < 10)
	{
		
		v1.insert(v1.begin() +k++, i++);
	}
	Print(v1);
	v1.pop_back();
	v1.pop_back();
	v1.pop_back();
	v1.pop_back();
	v1.pop_back();

	Print(v1);
	
	cout << "v1.size():" << v1.size() << endl;
	cout << "v1.capacity():" << v1.capacity() << endl;
	//vector能实现自动扩容但元素删除后不会自动缩小;

	vector<int> v2 = { 1,2,3 };
	auto p = v2.data();
	Print(v2);
	*p = 10;
	//Print(v2);
	cout<<*p++<<endl;
	*p = 20;
	Print(v2);

	vector<int> v3 = { 1,2,3 };
	Print(v3);
	v3.clear();//只清除元素不改变空间
	Print(v3);

	return 0;
}